package kz.vokebuz.dataStore;

import kz.vokebuz.R;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class WellcomCursorAdapter extends SimpleCursorAdapter {
	private static final String TAG = WellcomCursorAdapter.class
			.getSimpleName();
	private final Context mContext;
	private final int mLayout;
	private final Cursor mCursor;
	private final LayoutInflater mLayoutInflater;

	private final class ViewHolder {
		public TextView wellcomName;
		public TextView wellcomDetails;
	}

	public WellcomCursorAdapter(Context context, int layout, Cursor c,
			String[] from, int[] to) {
		super(context, layout, c, from, to);
		this.mContext = context;
		this.mLayout = layout;
		this.mCursor = c;
		this.mLayoutInflater = LayoutInflater.from(mContext);
		Log.d(TAG, "constructor !");
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		if (mCursor.moveToPosition(position)) {
			ViewHolder viewHolder;

			if (convertView == null) {
				convertView = mLayoutInflater.inflate(mLayout, null);

				viewHolder = new ViewHolder();
				viewHolder.wellcomDetails = (TextView) convertView
						.findViewById(R.id.rowWelcmCount);
				viewHolder.wellcomName = (TextView) convertView
						.findViewById(R.id.rowWelcName);

				convertView.setTag(viewHolder);

			} else {
				viewHolder = (ViewHolder) convertView.getTag();

			}

			viewHolder.wellcomName.setText(mCursor.getString(mCursor.getColumnIndex("categoryid")));
			String wDetailtemp = mCursor.getInt(mCursor
					.getColumnIndex("isread"))
					+ " of : "
					+ mCursor.getInt(mCursor.getColumnIndex("total"));

			viewHolder.wellcomDetails.setText(wDetailtemp);
		}
		return convertView;
	}

}
